<script setup>
import { statistics1Api, statistics2Api } from '@/api/index'
import { onMounted, ref } from 'vue'
import CountTo from '@/components/count-to.vue'
import IndexNavs from '@/components/index-navs.vue'
import IndexChart from '@/components/index-chart.vue'
import IndexCard from '@/components/index-card.vue'

//统计数据1
const panelsList = ref([])
const getstatistics1 = async () => {
  const res = await statistics1Api()
  panelsList.value = res.panels
}

const goods = ref([])
const order = ref([])

//获取统计数据2
const getstatistics2 = async () => {
  const res = await statistics2Api()
  goods.value = res.goods
  order.value = res.order
}

onMounted(() => {
  getstatistics1()
  getstatistics2()
})
</script>

<template>
  <div>
    <el-row :gutter="20">
      <!-- 骨架屏 -->
      <template v-if="panelsList.length === 0">
        <el-col :span="6" :offset="0" v-for="i in 4" :key="i">
          <el-skeleton style="width: 100%" animated loading>
            <template #template>
              <el-card shadow="hover">
                <template #header>
                  <div class="flex justify-between">
                    <el-skeleton-item variant="text" style="width: 50%" />
                    <el-skeleton-item variant="text" style="width: 10%" />
                  </div>
                </template>
                <el-skeleton-item variant="h3" style="width: 80%" />
                <el-divider />
                <div class="flex justify-between text-sm text-gray-500">
                  <el-skeleton-item variant="text" style="width: 50%" />
                  <el-skeleton-item variant="text" style="width: 10%" />
                </div>
              </el-card>
            </template>
          </el-skeleton>
        </el-col>
      </template>

      <el-col :span="6" :offset="0" v-for="(item, index) in panelsList" :key="index">
        <el-card shadow="hover">
          <template #header>
            <div class="flex justify-between">
              <span class="text-sm">{{ item.title }}</span>
              <el-tag :type="item.unitColor" effect="plain">{{ item.unit }}</el-tag>
            </div>
          </template>
          <span class="text-3xl font-bold text-gray-500">
            <CountTo :value="item.value"></CountTo>
          </span>
          <el-divider />
          <div class="flex justify-between text-sm text-gray-500">
            <span>{{ item.subTitle }}</span>
            <span>{{ item.subValue }}</span>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <IndexNavs></IndexNavs>
    <el-row :gutter="20">
      <el-col :span="12" :offset="0">
        <IndexChart></IndexChart>
      </el-col>
      <el-col :span="12" :offset="0">
        <IndexCard
          title="店铺及商品提示"
          tip="店铺及商品提示"
          :btns="goods"
          class="mb-3"
        ></IndexCard>
        <IndexCard title="交易提示" tip="需要立即处理的交易订单" :btns="order"></IndexCard>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped></style>
